package org.jyrcp.base;

import org.eclipse.core.runtime.IPlatformRunnable;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.python.util.PythonInterpreter;

public class JyRCPApplication implements IPlatformRunnable
{
	public static PythonInterpreter interpreter = new PythonInterpreter();

	public Object run(Object args) throws Exception
	{
		interpreter.exec("import sys");
		interpreter.exec("sys.path.append('C:\\Development\\workspace\\org.jyrcp.base\\demo')");
		interpreter.exec("from workbench.window import JyRCPWorkbenchAdvisor");
		interpreter.exec("workbenchAdvisor = JyRCPWorkbenchAdvisor()");
		
		WorkbenchAdvisor workbenchAdvisor = (WorkbenchAdvisor) interpreter.get(
				"workbenchAdvisor", WorkbenchAdvisor.class);

		Display display = PlatformUI.createDisplay();
		try
		{
			int returnCode = PlatformUI.createAndRunWorkbench(display, workbenchAdvisor);
			if (returnCode == PlatformUI.RETURN_RESTART)
			{
				return IPlatformRunnable.EXIT_RESTART;
			}
			return IPlatformRunnable.EXIT_OK;
			
		}
		finally
		{
			display.dispose();
		}
	}
}
